package cn.itcast.job;

import cn.itcast.domain.cargo.Export;
import cn.itcast.service.cargo.ExportService;
import cn.itcast.vo.ExportResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.cxf.jaxrs.client.WebClient;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("exportJob")
public class ExportJob {

    @Reference
    private ExportService exportService;

    public void exportE(){
        System.out.println("ExportJob.exportE execute.......");
//        查询state=5的报运单
        List<Export> exportList = exportService.findByState(5);
        System.out.println(exportList);
//        一个一个地查询海关项目 看是否有结果
        for (Export export : exportList) {
            try {
//                如果海关没有数据会报错，所以这里try catch
                ExportResult exportResult = WebClient.create("http://localhost:9090/ws/export/ep/" + export.getId()).get(ExportResult.class);
                if(exportResult!=null){
                    //        如果有结果 更新报运单状态以及货物的税
                    exportService.updateE(exportResult); //海关数据更新
                }
            } catch (Exception e) {
                System.out.println(export.getId()+" no result。。。。。。。。。。。。。。");
            }
        }
    }
}
